﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbFiler : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbFiler(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbFiler_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbFiler obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbFiler()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbFiler(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbFiler cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbFiler_cast(OdRxObject.getCPtr(pObj));
			OdDbFiler result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbFiler)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbFiler)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbFiler)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbFiler_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbFiler_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbFiler_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbFiler createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbFiler_createObject();
			OdDbFiler result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbFiler)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbFiler)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbFiler)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult filerStatus()
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbFiler_filerStatus(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void resetFilerStatus()
		{
			TD_DbPINVOKE.OdDbFiler_resetFilerStatus(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdDbFiler.FilerType filerType()
		{
			OdDbFiler.FilerType result = (OdDbFiler.FilerType)TD_DbPINVOKE.OdDbFiler_filerType(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdDbDatabase database()
		{
			OdDbDatabase result = (OdDbDatabase)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbFiler_database(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual DwgVersion dwgVersion(out MaintReleaseVer pMaintReleaseVer)
		{
			DwgVersion result = (DwgVersion)TD_DbPINVOKE.OdDbFiler_dwgVersion__SWIG_0(this.swigCPtr, out pMaintReleaseVer);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual DwgVersion dwgVersion()
		{
			DwgVersion result = (DwgVersion)TD_DbPINVOKE.OdDbFiler_dwgVersion__SWIG_1(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbAuditInfo getAuditInfo()
		{
			IntPtr intPtr = TD_DbPINVOKE.OdDbFiler_getAuditInfo(this.swigCPtr);
			OdDbAuditInfo result = (intPtr == IntPtr.Zero) ? null : new OdDbAuditInfo(intPtr, false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void setController(OdDbFilerController pFilerController)
		{
			TD_DbPINVOKE.OdDbFiler_setController(this.swigCPtr, OdDbFilerController.getCPtr(pFilerController));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdDbFilerController controller()
		{
			IntPtr intPtr = TD_DbPINVOKE.OdDbFiler_controller(this.swigCPtr);
			OdDbFilerController result = (intPtr == IntPtr.Zero) ? null : new OdDbFilerController(intPtr, false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		public enum FilerType
		{
			kFileFiler,
			kCopyFiler,
			kUndoFiler,
			kBagFiler,
			kIdXlateFiler,
			kPageFiler,
			kDeepCloneFiler,
			kIdFiler,
			kPurgeFiler,
			kWblockCloneFiler
		}
	}
}
